In JavaScript, both arrays and objects are used to store collections of data. However, they differ in how they store and access that data.
0.Example:
let fruits = ["Apple", "Banana", "Cherry"];
console.log(fruits[1]);
Output: Banana
Example:
let person = {
name: "John",
age: 30,
job: "Developer" };
console.log(person.name);
Output: John
| Aspect | Array | Object |
|---|---|---|
| Data Structure | Ordered list | Key-value pairs |
| Access | By numeric index | By key |
| Use Case | Storing lists of items | Representing structured data |
| Methods | Array-specific methods like push, pop |
Object-specific methods like Object.keys, Object.values |